package com.example.mvc.controller;

import com.example.mvc.bean.Book;
import com.example.mvc.bean.User;
import com.example.mvc.service.BookService;
import com.example.mvc.service.UserService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
//添加读者
@WebServlet("/addReadUserServlet")
public class AddReadUserServlet extends HttpServlet {
    UserService userService = new UserService();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String name = request.getParameter("name");
        String email = request.getParameter("email");
        String phone = request.getParameter("phone");
        int lend_num = Integer.parseInt(request.getParameter("lend_num"));
        int max_num = Integer.parseInt(request.getParameter("max_num"));
        User readUser = new User();
        readUser.setUsername(username);
        readUser.setPassword(password);
        readUser.setName(name);
        readUser.setEmail(email);
        readUser.setPhone(phone);
        readUser.setLend_num(lend_num);
        readUser.setMax_num(max_num);
        boolean addSuccess = userService.addReadUser(readUser);
        String contextPath = request.getContextPath();
        resp.sendRedirect(contextPath+"/getUserList");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
}
